﻿/*
 * Created by SharpDevelop.
 * User: ratul
 * Date: 3/2/2010
 * Time: 8:05 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections;
using System.Collections.Generic;
using H264Impl.NET.NAL;
using H264Impl.NET.Coding;


namespace H264Impl.NET.Slice
{
	/// <summary>
	/// Description of Slice.
	/// </summary>
	public class BaseSlice
	{
		public BaseSlice(Decoder.CodedPicture parentCodedPicture)
		{
			this.parentCodedPicture = parentCodedPicture;
		}
		
		
		public void parseSliceLayerWithoutPartitioningRBSP(NAL.NALUnit _NALUnit, BitStream RBSP, UInt32 firstMbInSlice, UInt32 picParameterSetId)
		{
			parseSliceHeader(_NALUnit, RBSP, firstMbInSlice, picParameterSetId);
		}
		
		public void parseSliceHeader(NAL.NALUnit _NALUnit, BitStream RBSP, UInt32 firstMbInSlice, UInt32 picParameterSetId)
		{
			this.firstMbInSlice = firstMbInSlice;
			this.picParameterSetId = picParameterSetId;
			
			if(parentCodedPicture.getSeparateColorPlaneFlag())
				colourPlaneId = RBSP.getBits(2);
			frameNum = RBSP.getBits((UInt16)(parentCodedPicture.getLog2MaxFrameNumMinus4()+4));
			if(!(parentCodedPicture.getFrameMbsOnlyFlag()))
			{
				fieldPicFlag = RBSP.getBit();
				if(fieldPicFlag)
					bottomFieldFlag = RBSP.getBit();
			}
			
			if(_NALUnit.getIDRPicFlag())
				idrPicId = ExpGolomb.getUnsignedIntegerElement(RBSP);
			
			if(parentCodedPicture.getPicOrderCntType()==0)
			{
				picOrderCntLsb = RBSP.getBits((UInt16)(parentCodedPicture.getLog2MaxPicOrderCntLsbMinus4() + 4));
				if(parentCodedPicture.getBottomFieldPicOrderInFramePresentFlag() && !fieldPicFlag)
					deltaPicOrderCntBottom = ExpGolomb.getSignedIntegerElement(RBSP);
			}
			if(parentCodedPicture.getPicOrderCntType()==1 && !parentCodedPicture.getDeltaPicOrderAlwaysZeroFlag())
			{
				deltaPicOrderCnt = new Int32[2];
				deltaPicOrderCnt[0] = ExpGolomb.getSignedIntegerElement(RBSP);
				if(parentCodedPicture.getBottomFieldPicOrderInFramePresentFlag() && !fieldPicFlag)
					deltaPicOrderCnt[1] = ExpGolomb.getSignedIntegerElement(RBSP);
			}
			if(parentCodedPicture.getRedundantPicCntPresentFlag())
				redundantPicCnt = ExpGolomb.getUnsignedIntegerElement(RBSP);
			
			//if(
		
		}
			
		protected Decoder.CodedPicture parentCodedPicture;
		
		protected List<Macroblock> macroblockList;
		protected UInt32 firstMbInSlice;
		//UInt32 sliceType;
		protected UInt32 picParameterSetId;
		protected UInt32 colourPlaneId;
		protected UInt32 frameNum;
		protected bool fieldPicFlag;
		protected bool bottomFieldFlag;
		protected UInt32 idrPicId;
		protected UInt32 picOrderCntLsb;
		protected Int32 deltaPicOrderCntBottom;
		protected Int32[] deltaPicOrderCnt;
		protected UInt32 redundantPicCnt;
		protected bool directSpatialMvPredFlag;
		protected bool numRefIdxActiveOverrideFlag;
		protected UInt32 numRefIdxl0ActiveMinus1;
		protected UInt32 numRefIdxl1ActiveMinus1;
		protected UInt32 cabacInitIdc;
		protected UInt32 sliceQpDelta;
		protected bool spForSwitchFlag;
		protected UInt32 sliceQsDelta;
		protected UInt32 disableDeblockingFilterIdc;
		protected UInt32 sliceAlphaC0OffsetDiv2;
		protected UInt32 sliceBetaOffsetDiv2;
		protected UInt32 sliceGroupChangeCycle;
		
	}
}
